{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "# 走迷宫\n",
    "    给定一个N×M的网格迷宫G。G的每个格子要么是道路，要么是障碍物（道路用1表示，障碍物用0表示）。已知迷宫的入口位置为(x1,y1)，出口位置为(x2,y2)。问从入口走到出口，最少要走多少个格子。\n",
    "    输入描述\n",
    "    输入第1行包含两个正整数N,M，分别表示迷宫的大小。接下来输入一个N×M的矩阵。若Gi,j=1 表示其为道路，否则表示其为障碍物。最后一行输入四个整数x1,y1,x2,y2，表示入口的位置和出口的位置。1≤N,M≤10**2，0≤Gi,j≤1，1≤x1,x2≤N，1≤y1，y2<= M\n",
    "    输出描述\n",
    "    输出仅一行，包含一个整数表示答案。若无法从入口到出口，则输出−1。"
   ],
   "id": "cf26332671c6b1f8"
  },
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-03-17T12:19:24.018759Z",
     "start_time": "2025-03-17T12:18:44.476168Z"
    }
   },
   "source": [
    "from pickletools import read_string4\n",
    "\n",
    "#队列 先进先出\n",
    "#道路为1，障碍为0\n",
    "n, m = map(int, input().split())  #读取输入的第一行，包含两个整数 n 和 m，分别表示网格的行数和列数\n",
    "gra = [list(map(int, input().split())) for i in range(n)] #    使用列表推导式读取接下来的 n 行输入，每行包含 m 个整数，表示网格的每个单元格的值。gra 是一个二维列表，表示整个网格。\n",
    "dirs = [[1, 0], [-1, 0], [0, 1], [0, -1]] #dirs 是一个二维列表，表示四个可能的移动方向：下，上，右，左   x轴对应列，y轴对应行\n",
    "x1, y1, x2, y2 = map(int, input().split()) #x1, y1, x2, y2，分别表示起点和终点的坐标。坐标从 1 开始，因此在实际使用时需要减去 1，将其转换为从 0 开始的索引。   \n",
    "q = [[x1 - 1, y1 - 1, 0]]  #当前点的坐标和步数。\n",
    "f = True#f 用于标记是否找到终点。初始值为 True，表示尚未找到终点。\n",
    "while q:\n",
    "    x, y, dis = q.pop(0) # 从队列中取出一个状态\n",
    "    if x == x2 - 1 and y == y2 - 1: # 检查是否到达终点\n",
    "        f = False\n",
    "        print(dis) # 输出步数\n",
    "        break\n",
    "    for xx, yy in dirs: # 遍历所有可能的移动方向\n",
    "        tx, ty = xx + x, yy + y # 计算新坐标\n",
    "        if tx >= 0 and tx < n and ty >= 0 and ty < m and gra[tx][ty] == 1: # 检查新坐标是否有效\n",
    "            gra[tx][ty] = 0   # 标记为已访问\n",
    "            q.append([tx, ty, dis+1]) # 将新状态加入队列\n",
    "if f: print(-1)  # 如果未找到终点"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-18T04:54:27.349546Z",
     "start_time": "2025-03-18T04:54:19.504849Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import os\n",
    "import sys\n",
    "\n",
    "# 请在此输入您的代码\n",
    "n=int(input())\n",
    "lst=list(map(int,input().split()))\n",
    "lst.sort()\n",
    "total=0\n",
    "temp=0\n",
    "for i in lst:\n",
    "    total+=i\n",
    "    if total>n:\n",
    "        temp=i\n",
    "        break\n",
    "print(lst.index(temp)-1)"
   ],
   "id": "8078dc40383f2a8c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-18T12:57:53.986422Z",
     "start_time": "2025-03-18T12:57:53.974595Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import os\n",
    "import sys\n",
    "\n",
    "# 请在此输入您的代码\n",
    "#1肯定是消耗最快的\n",
    "num=0\n",
    "for i in range(1,10000):\n",
    "    num+=str(i).count('1')\n",
    "    if num>2021:  #1一共2021个\n",
    "        break\n",
    "print(i-1)"
   ],
   "id": "20b5ae36fa1b8f07",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3181\n"
     ]
    }
   ],
   "execution_count": 16
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "### 数字三角形(动态规划)\n",
    "    从三角形的顶部到底部有很多条不同的路径。对于每条路径，把路径上面的数加起来可以得到一个和，你的任务就是找到最大的和。路径上的每一步只能从一个数走到下一层和它最近的左边的那个数或者右 边的那个数。此外，向左下走的次数与向右下走的次数相差不能超过 1。\n",
    "    \n",
    "    输入描述\n",
    "    输入的第一行包含一个整数N(1≤N≤100)，表示三角形的行数。下面的N行给出数字三角形。数字三角形上的数都是 0 至 100 之间的整数。\n",
    "    输出描述\n",
    "    输出一个整数，表示答案。\n",
    "    "
   ],
   "id": "961a7e12e4a1c684"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "        7                      7\n",
    "       3 8                     3 8\n",
    "      8 1 0  输入是这样的->     8 1 0\n",
    "     2 7 4 4                   2 7 4 4\n",
    "    4 5 2 6 5                  4 5 2 6 5            #27"
   ],
   "id": "8204ea6b3b9c4bd2"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-20T01:35:15.446919Z",
     "start_time": "2025-03-20T01:34:52.273583Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#有点难再看看\n",
    "n=int(input())\n",
    "h=[list(map(int,input().split())) for i in range(n)]  #第一行，第二行，第三行...第n行  [[7],[3,8]...]\n",
    "for i in range(1,n):#遍历行  动态规划的更新是从第二行开始的\n",
    "    for j in range(i+1):  #列数是行数+1\n",
    "        #先考虑最左边的情况，因为由题知只能往下走或者右下,最左边只能由右上得到\n",
    "        if j==0:  #最左边  只能从[i-1][j]得到\n",
    "            h[i][j]+=h[i-1][j]\n",
    "        elif j==i:#最右边同理 [i-1][j-1]\n",
    "            h[i][j]+=h[i-1][j-1]\n",
    "        else:  #切片取最大 动态规划的核心core!\n",
    "            h[i][j]+=max(h[i-1][j-1:j+1]) #j只能从上一行的j-1和j得到,j的下标索引j+1\n",
    "\"\"\"现在最后一行是各路径累加下来的值了，取最大就行x 不能直接取最大  题干说明路径的左右下走的次数相差不能超过1，路径必须大致平衡地向左下和向右下移动 最终路径的终点会集中在最后一行的中间位置。奇数行的情况：如果三角形的行数 h 是奇数，最后一行的元素数量也是奇数。路径的终点会集中在中间位置。  偶数行的情况：如果三角形的行数 h 是偶数，最后一行的元素数量是偶数。路径的终点会集中在中间两个位置之一。\"\"\"\n",
    "#结果一定不会是累加之后最左边或最右边的，因为最左边只能由上方得到然后得到的数还是最左方，他就一直是下下下下，同理右方也是\n",
    "if n&1==0: #偶数行 要获取  按位与&同1为1\n",
    "    print(max(h[n-1][n//2-1],w[n-1][n//2]))  #下标索引，这里要-1哦，或者直接取-1表示最后一行\n",
    "else:  #奇数行\n",
    "    print(h[n-1][n//2])\n",
    "\n",
    "     \n",
    "\n"
   ],
   "id": "d337356b8c42506a",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "27\n"
     ]
    }
   ],
   "execution_count": 12
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-20T01:29:20.959665Z",
     "start_time": "2025-03-20T01:29:20.951865Z"
    }
   },
   "cell_type": "code",
   "source": "print(2&1)\n",
   "id": "57e131e1e3daae3",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n"
     ]
    }
   ],
   "execution_count": 10
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-20T01:11:29.440695Z",
     "start_time": "2025-03-20T01:11:29.420941Z"
    }
   },
   "cell_type": "code",
   "source": "print(11//3)  #相当于[x] not四舍五入，直接去尾 取整操作  上面的还有一个注意点，索引哦要再-1",
   "id": "517346daf80280aa",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-19T14:43:43.713213Z",
     "start_time": "2025-03-19T14:43:24.066895Z"
    }
   },
   "cell_type": "code",
   "source": [
    "w=[list(map(int,input().split()))  for i in range(5)]\n",
    "print(*w)\n",
    "\"\"\"\n",
    "动态规划！\n",
    "假设我们有以下数字三角形：\n",
    "    3\n",
    "   7 4\n",
    "  2 4 6\n",
    " 8 5 9 3\n",
    "初始化\n",
    "W 的初始状态：\n",
    "[\n",
    "  [3],\n",
    "  [7, 4],\n",
    "  [2, 4, 6],\n",
    "  [8, 5, 9, 3]\n",
    "]\n",
    "更新过程\n",
    "    第 1 行：\n",
    "        W[1][0] 只能从 W[0][0] 到达：W[1][0] += W[0][0] → 7 + 3 = 10\n",
    "        W[1][1] 只能从 W[0][0] 到达：W[1][1] += W[0][0] → 4 + 3 = 7\n",
    "        更新后的 W：\n",
    "    [\n",
    "      [3],\n",
    "      [10, 7],\n",
    "      [2, 4, 6],\n",
    "      [8, 5, 9, 3]\n",
    "    ]\n",
    "    \n",
    "    第 2 行：\n",
    "        W[2][0] 只能从 W[1][0] 到达：W[2][0] += W[1][0] → 2 + 10 = 12\n",
    "        W[2][1] 可以从 W[1][0] 或 W[1][1] 到达，选择较大的 W[1][0]：W[2][1] += max(W[1][0], W[1][1]) → 4 + 10 = 14\n",
    "        W[2][2] 只能从 W[1][1] 到达：W[2][2] += W[1][1] → 6 + 7 = 13\n",
    "        更新后的 W：\n",
    "    [\n",
    "      [3],\n",
    "      [10, 7],\n",
    "      [12, 14, 13],\n",
    "      [8, 5, 9, 3]\n",
    "    ]\n",
    "\n",
    "    第 3 行：\n",
    "        W[3][0] 只能从 W[2][0] 到达：W[3][0] += W[2][0] → 8 + 12 = 20\n",
    "        W[3][1] 可以从 W[2][0] 或 W[2][1] 到达，选择较大的 W[2][1]：W[3][1] += max(W[2][0], W[2][1]) → 5 + 14 = 19\n",
    "        W[3][2] 可以从 W[2][1] 或 W[2][2] 到达，选择较大的 W[2][1]：W[3][2] += max(W[2][1], W[2][2]) → 9 + 14 = 23\n",
    "        W[3][3] 只能从 W[2][2] 到达：W[3][3] += W[2][2] → 3 + 13 = 16\n",
    "        更新后的 W：\n",
    "    [\n",
    "      [3],\n",
    "      [10, 7],\n",
    "      [12, 14, 13],\n",
    "      [20, 19, 23, 16]\n",
    "    ]\n",
    "\n",
    "最终结果\n",
    "根据行数 h 的奇偶性，从最后一行中选择最大路径和：\"\"\""
   ],
   "id": "b24014cd75a5fe83",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[7] [3, 8] [8, 1, 0] [2, 7, 4, 4] [4, 5, 2, 6, 5]\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "",
   "id": "673ac4e253948496"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-20T09:57:10.253280Z",
     "start_time": "2025-03-20T09:57:02.126130Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import os\n",
    "import sys\n",
    "# 请在此输入您的代码\n",
    "n=2021041820210418\n",
    "lst=[]\n",
    "for i in range(1,int(n**(1/2))+1):\n",
    "    if n%i==0:\n",
    "        lst.append(i)\n",
    "        if n/i !=i:\n",
    "            lst.append(n/i)\n",
    "count=0\n",
    "for i in lst:\n",
    "    for j in lst:\n",
    "        for k in lst:\n",
    "            if i*j*k==n:\n",
    "                count+=1\n",
    "print(count)"
   ],
   "id": "36bca888d7abff3d",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2430\n"
     ]
    }
   ],
   "execution_count": 13
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "### 答疑\n",
    "    有n位同学同时找老师答疑。每位同学都预先估计了自己答疑的时间。老师可以安排答疑的顺序，同学们要依次进入老师办公室答疑。 一位同学答疑的过程如下：\n",
    "    1.首先进入办公室，编号为i的同学需要si毫秒的时间。\n",
    "    2.然后同学问问题老师解答，编号为i的同学需要ai毫秒的时间。\n",
    "    3.答疑完成后，同学很高兴，会在课程群里面发一条消息，需要的时间可以忽略。\n",
    "    4.最后同学收拾东西离开办公室，需要ei毫秒的时间。一般需要10秒、20秒或30秒，即ei取值为10000，20000或30000。\n",
    "    \n",
    "    一位同学离开办公室后，紧接着下一位同学就可以进入办公室了。答疑从0时刻开始。老师想合理的安排答疑的顺序，使得同学们在课程群里面发消息的时刻之和最小。\n",
    "    输入描述\n",
    "    输入第一行包含一个整数n，表示同学的数量。接下来n行，描述每位同学的时间。其中第i行包含三个整数si,ai,ei，意义如上所述。其中有1≤n≤1000，1≤si≤60000，1≤ai≤10**6，ei∈10000,20000,30000，即ei一定是10000、20000、30000 之一。\n",
    "    输出描述\n",
    "    输出一个整数，表示同学们在课程群里面发消息的时刻之和最小是多少。"
   ],
   "id": "2e57d68d95918c2f"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-21T00:23:46.840938Z",
     "start_time": "2025-03-21T00:23:25.535536Z"
    }
   },
   "cell_type": "code",
   "source": [
    "n=int(input())\n",
    "A=[]\n",
    "for i in range(n):\n",
    "    a,b,c=map(int,input().split())\n",
    "    t1=a+b#进办公室+答疑时间\n",
    "    t2=a+b+c #这个学生需要用的总时间\n",
    "    A.append([t1,t2])\n",
    "B=sorted(A,key=lambda x:x[1],reverse=False)  #这里应该按总时间排序\n",
    "t=B[0][0]\n",
    "delta=B[0][1]\n",
    "for i in range(1,n):\n",
    "    t+=delta\n",
    "    t+=B[i][0]\n",
    "    delta+=B[i][1]\n",
    "print(t)"
   ],
   "id": "af855742053c745e",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "280000\n"
     ]
    }
   ],
   "execution_count": 25
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-21T00:07:22.862913Z",
     "start_time": "2025-03-21T00:06:56.442640Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import os\n",
    "import sys\n",
    "\n",
    "# 请在此输入您的代码\n",
    "n=int(input())  #同学的数量\n",
    "A=[]\n",
    "for i in range(n):\n",
    "    a,b,c=map(int,input().split()) #a:进入 b:答疑 c:离开\n",
    "    t1=a+b\n",
    "    t2=a+b+c\n",
    "    A.append([t1,t2])\n",
    "B=sorted(A,key=lambda x:x[1])   #这里要按总时间来排序\n",
    "s=B[0][0]\n",
    "t=0\n",
    "delta=B[0][1]\n",
    "for i in range(1,n):\n",
    "    s+=delta\n",
    "    s+=B[i][0]\n",
    "    delta+=B[i][1]\n",
    "print(s)\n",
    "#终于QAQ！！！      "
   ],
   "id": "9b0358c6ed8921bb",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "280000\n"
     ]
    }
   ],
   "execution_count": 23
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-21T01:10:56.885526Z",
     "start_time": "2025-03-21T01:10:52.693609Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import os\n",
    "import sys\n",
    "import datetime\n",
    "# 请在此输入您的代码\n",
    "start=datetime.datetime(1900,1,1)\n",
    "end=datetime.datetime(9999,12,31)\n",
    "t=datetime.timedelta(days=1)\n",
    "count=0\n",
    "while start<end:\n",
    "    y=start.year\n",
    "    m=start.month\n",
    "    d=start.day\n",
    "    y1=0\n",
    "    m1=0\n",
    "    d1=0\n",
    "    if (y//1000)+(y//100-(y//1000)*10)+((y%100)//10)+(y%10)==(m//10)+(m%10)+(d%10)+(d//10):\n",
    "        count+=1\n",
    "    start+=t\n",
    "print(count)"
   ],
   "id": "abd74649fd9b3cf5",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "70910\n"
     ]
    }
   ],
   "execution_count": 30
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "s = datetime(1900, 1, 1)\n",
    "e = datetime(9999, 12, 31)\n",
    "t = timedelta(days=1)\n",
    "summ = 0\n",
    "while s < e:\n",
    "    y = int(s.year)\n",
    "    m = int(s.month)\n",
    "    d = int(s.day)\n",
    "    n = y//1000 + ((y//10) % 10) + y % 10 + ((y//100) % 10)\n",
    "    m = m % 10 + m//10 + d % 10 + d//10\n",
    "    if m == n:\n",
    "        summ += 1\n",
    "    s += t\n",
    "print(summ)"
   ],
   "id": "e5859cfb29f40ae3"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-21T00:36:10.263987Z",
     "start_time": "2025-03-21T00:36:10.244598Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import datetime\n",
    "# 请在此输入您的代码\n",
    "start=datetime.datetime(1900,1,1)\n",
    "print(start)\n",
    "print(type(start))"
   ],
   "id": "ef72431c0b2c69f3",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1900-01-01 00:00:00\n",
      "<class 'datetime.datetime'>\n"
     ]
    }
   ],
   "execution_count": 27
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "### 数位排序\n",
    "    小蓝对一个数的数位之和很感兴趣,今天他要按照数位之和给数排序。当两个数各个数位之和不同时,将数位和较小的排在前面,当数位之和相等时,将数值小的排在前面。例如,2022排在409前面,因为2022的数位之和是6,小于409的数位之和13.又如,6排在2022前面,因为它们的数位之和相同,而6小于2022 。给定正整数n,m,请问对1到n采用这种方法排序时, 排在第m个的元素是多少?\n",
    "    输入格式\n",
    "    输入第一行包含一个正整数n.第二行包含一个正整数m。\n",
    "    输出格式\n",
    "    输出一行包含一个整数, 表示答案。"
   ],
   "id": "87b3260a87d6471c"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-22T05:28:38.628960Z",
     "start_time": "2025-03-22T05:28:34.198956Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#这个也再看看啦\n",
    "n=int(input())\n",
    "m=int(input())\n",
    "lst=list(range(1,n+1))\n",
    "lst.sort(key=lambda x: sum(int(i) for i in str(x)))\n",
    "print(lst[m-1])"
   ],
   "id": "ad1418d8c22f7b04",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "execution_count": 38
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-22T05:15:58.438876Z",
     "start_time": "2025-03-22T05:15:58.419110Z"
    }
   },
   "cell_type": "code",
   "source": [
    "s=list(range(1,5))\n",
    "print(s)"
   ],
   "id": "14b49d3429ef3098",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4]\n"
     ]
    }
   ],
   "execution_count": 34
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-22T05:21:30.138522Z",
     "start_time": "2025-03-22T05:21:30.124384Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a=sum(int(i) for i in str('1543'))\n",
    "print(a)"
   ],
   "id": "8339a8e92a260aab",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13\n"
     ]
    }
   ],
   "execution_count": 36
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "### 数位递增\n",
    "    一个正整数如果任何一个数位不大于右边相邻的数位，则称为一个数位递增的数。例如1135是一个数位递增的数，而1024不是一个数位递增的数。给定正整数n，请问在整数1至n中有多少个数位递增的数？\n",
    "    输入描述\n",
    "    输入的第一行包含一个整数n(1<n<10**6)。\n",
    "    输出描述\n",
    "    输出一行包含一个整数，表示答案。"
   ],
   "id": "f1059e52b7be1cb8"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-22T07:38:48.553064Z",
     "start_time": "2025-03-22T07:38:46.182413Z"
    }
   },
   "cell_type": "code",
   "source": [
    "n=int(input())\n",
    "count=0\n",
    "for i in range(1,n+1):\n",
    "    l1=str(i)\n",
    "    l2=sorted(l1)\n",
    "    if l2==list(l1):\n",
    "        count+=1\n",
    "print(count) "
   ],
   "id": "b13f967148eb7066",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "26\n"
     ]
    }
   ],
   "execution_count": 60
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-22T07:33:03.108398Z",
     "start_time": "2025-03-22T07:33:03.098070Z"
    }
   },
   "cell_type": "code",
   "source": [
    "str1=\"1435\"\n",
    "str2=\"8976\"\n",
    "\n",
    "str3=sorted(str2)\n",
    "print(type(str3))\n",
    "print(str3)"
   ],
   "id": "f8e3106d4a5d4be3",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'list'>\n",
      "['6', '7', '8', '9']\n"
     ]
    }
   ],
   "execution_count": 55
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-22T07:32:27.095657Z",
     "start_time": "2025-03-22T07:32:24.995615Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import os\n",
    "import sys\n",
    "\n",
    "# 请在此输入您的代码\n",
    "n=int(input())\n",
    "count=0\n",
    "for i in range(1,n+1):\n",
    "    num=str(i)\n",
    "    s=sorted(num)\n",
    "    # lst=[]\n",
    "    # for i in s:\n",
    "    #     lst.append(i)\n",
    "    if list(num)==s:\n",
    "        count+=1\n",
    "print(count)"
   ],
   "id": "336c534c05a59a1f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "26\n"
     ]
    }
   ],
   "execution_count": 54
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "### 穿越时空之门\n",
    "    问题描述 \n",
    "    随着2024年的钟声回荡，传说中的时空之门再次敞开。这扇门是一条神秘的通道，它连接着二进制和四进制两个不同的数码领域，等待着勇者们的探索。在二进制的领域里，勇者的力量被转换成了力量数值的二进制表示中各数位之和。在四进制的领域里，力量的转换规则相似，变成了力量数值的四进制表示中各数位之和。穿越这扇时空之门的条件是严苛的：当且仅当勇者在二进制领域的力量等同于四进制领域的力量时，他才能够成功地穿越。国王选定了小蓝作为领路人，带领着力量值从1到2024的勇者们踏上了这段探索未知的旅程。作为小蓝的助手，你的任务是帮助小蓝计算出，在这2024位勇者中，有多少人符合穿越时空之门的条件。\n",
    "    答案提交\n",
    "    这是一道结果填空题，你只需要算出结果后提交即可。本题的结果为一个整数，在提交答案时只填写这个整数，填写多余的内容将无法得分。"
   ],
   "id": "3dde3303e15a6b1b"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-24T07:14:49.693304Z",
     "start_time": "2025-03-24T07:14:49.665999Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#二进制\n",
    "def func_2(num):\n",
    "    s2=bin(num)[2:]\n",
    "    res2=0\n",
    "    for i in s2:\n",
    "        res2+=int(i)\n",
    "    return res2\n",
    "\n",
    "#四进制\n",
    "def func_4(num):\n",
    "    digits=\"0123\"\n",
    "    s4=\"\"\n",
    "    while num>0:\n",
    "        yu=num%4\n",
    "        s4=digits[yu]+s4\n",
    "        num//=4\n",
    "    res4=0\n",
    "    for j in s4:\n",
    "        res4+=int(j)\n",
    "    return res4\n",
    "\n",
    "count=0\n",
    "for k in range(1,2025):\n",
    "    if func_2(k)==func_4(k):\n",
    "        count+=1\n",
    "print(count)"
   ],
   "id": "8185f6f62d996f11",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "63\n"
     ]
    }
   ],
   "execution_count": 68
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-24T06:46:50.559184Z",
     "start_time": "2025-03-24T06:46:50.535704Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#十转四\n",
    "digits=\"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n",
    "start=10\n",
    "result=\"\"\n",
    "while start>0:\n",
    "    yu=start%4\n",
    "    result=digits[yu]+result\n",
    "    start//=4\n",
    "print(result)\n",
    "    "
   ],
   "id": "893bea7b64bc47e1",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "22\n"
     ]
    }
   ],
   "execution_count": 63
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-24T06:46:13.084171Z",
     "start_time": "2025-03-24T06:46:12.973531Z"
    }
   },
   "cell_type": "code",
   "source": [
    "str1=\"123\"\n",
    "str2=\"456\"\n",
    "print(str1+str2)\n",
    "print(str2+str1)"
   ],
   "id": "85c89fd988c19a49",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123456\n",
      "456123\n"
     ]
    }
   ],
   "execution_count": 62
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-24T07:36:32.085608Z",
     "start_time": "2025-03-24T07:36:03.194259Z"
    }
   },
   "cell_type": "code",
   "source": [
    "l=[]\n",
    "for i in range(3):  #n 行\n",
    "    l.append([])\n",
    "    for j in range(3):\n",
    "        l[i].append(input())\n",
    "print(l)"
   ],
   "id": "5b84486f9d48b2c8",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]\n"
     ]
    }
   ],
   "execution_count": 80
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "### 字符串个数\n",
    "    问题描述\n",
    "    小蓝想要构造出一个长度为10000的数字字符串，有以下要求:小蓝不喜欢数字0，所以数字字符串中不可以出现0;小蓝喜欢数字3和7，所以数字字符串中必须要有3和7这两个数字。请问满足题意的数字字符串有多少个？这个数字会很大，你只需要输出其对10**9+7取余后的结果。\n",
    "    答案提交\n",
    "    这是一道结果填空的题，你只需要算出结果后提交即可。本题的结果为一个整数，在提交答案时只填写这个整数，填写多余的内容将无法得分。"
   ],
   "id": "8cd8349e9ba5bf"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-24T08:38:08.212926Z",
     "start_time": "2025-03-24T08:38:08.189486Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import math\n",
    "#总的 123456789  9种情况\n",
    "n1=9**10000\n",
    "#没7/没8  12345689 12345679\n",
    "n2=8**10000*2\n",
    "#没7中含没7没8 没8种也含没7没8 所以要加上一个\n",
    "#没7没8 1234569\n",
    "n3=7**10000\n",
    "n=n1-n2+n3\n",
    "print(n%(10**9+7))"
   ],
   "id": "d595279d3f39f5a9",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "157509472\n"
     ]
    }
   ],
   "execution_count": 87
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-24T10:14:02.171670Z",
     "start_time": "2025-03-24T10:14:02.137565Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import datetime\n",
    "a='2016-09-07'\n",
    "b='18:24:33'\n",
    "time=datetime.datetime.strptime(a+' '+b,'%Y-%m-%d %H:%M:%S')\n",
    "print(time)\n",
    "print(type(time))"
   ],
   "id": "d5a6d95cecee5f0b",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2016-09-07 18:24:33\n",
      "<class 'datetime.datetime'>\n"
     ]
    }
   ],
   "execution_count": 92
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "### 神奇闹钟\n",
    "    问题描述\n",
    "    小蓝发现了一个神奇的闹钟，从纪元时间（1970年1月1日00：00：00）开始，每经过x分钟，这个闹钟便会触发一次闹铃 (纪元时间也会响铃)。这引起了小蓝的兴趣，他想要好好研究下这个闹钟。对于给出的任意一个格式为уууу-MM-ddHH:mm:ss的时间，小蓝想要知道在这个时间点之前 (包含这个时间点) 的最近的一次闹铃时间是哪个时间?注意，你不必考虑时区问题。\n",
    "    输入格式\n",
    "    输入的第一行包含一个整数T，表示每次输入包含T组数据。接下来依次描述T组数据。每组数据一行，包含一个时间（格式为уууу-MM-ddHH:mm:ss）和一个整数x，其中x表示闹铃时间间隔（单位为分钟）。\n",
    "    输出格式\n",
    "    输出T行，每行包含一个时间（格式为 уууу-MM-ddHH:mm:ss），依次表示每组数据的答案。\n"
   ],
   "id": "b41665a1ad1e3db4"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-24T11:19:46.467928Z",
     "start_time": "2025-03-24T11:19:13.381988Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import datetime\n",
    "t=int(input())\n",
    "for _ in range(t):\n",
    "    a,b,c=input().split()\n",
    "    time=datetime.datetime.strptime(a+' '+b,'%Y-%m-%d %H:%M:%S')\n",
    "    x=int(c)\n",
    "    t=datetime.datetime(1970,1,1,0,0,0)\n",
    "    delta=time-t\n",
    "    d=(delta.total_seconds()//60)%x   #total_seconds()是获取时间间隔的总秒数\n",
    "    finaltime=time-datetime.timedelta(minutes=d)\n",
    "    print(finaltime.replace(second=0))\n",
    "    "
   ],
   "id": "8c78bc25a1845eab",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2016-09-07 18:20:00\n",
      "2037-01-05 01:30:00\n"
     ]
    }
   ],
   "execution_count": 93
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "",
   "id": "65303fd5ef3bdff8"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
